package gui;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

import algorythm.Piece;
import algorythm.Piece.Color;
import algorythm.Piece.PieceType;

@SuppressWarnings("serial")
public class PieceRepresentation extends JLabel {

	Piece representingPiece;

	public PieceRepresentation(Piece pieceToRepresent) {
		representingPiece = pieceToRepresent;
		setImageForType(representingPiece.getType());
	}

	public void setImageForType(PieceType newType) {
		switch (newType) {
		case PAWN:
			if (representingPiece.getColor() == Color.WHITE) {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/White Pawn.png")));
			} else {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/Black Pawn.png")));
			}
			break;
		case TOWER:
			if (representingPiece.getColor() == Color.WHITE) {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/White Tower.png")));
			} else {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/Black Tower.png")));
			}
			break;
		case KNIGHT:
			if (representingPiece.getColor() == Color.WHITE) {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/White Horse.png")));
			} else {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/Black Horse.png")));
			}
			break;
		case BISHOP:
			if (representingPiece.getColor() == Color.WHITE) {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/White Bishop.png")));
			} else {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/Black Bishop.png")));
			}
			break;
		case KING:
			if (representingPiece.getColor() == Color.WHITE) {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/White King.png")));
			} else {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/Black King.png")));
			}
			break;
		case QUEEN:	
			if (representingPiece.getColor() == Color.WHITE) {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/White Queen.png")));
			} else {
				this.setIcon(new ImageIcon(this.getClass().getResource("/images/Black Queen.png")));
			}
			break;
		}
	}
	
	public Piece getRepresentingPiece() {
		return representingPiece;
	}

}
